<script>
$(document).ready(function(){
	
	var c = {
		inits:function(){
			js.ajax.get('api/home/index', function(ret){
				c.showdata(ret.data);
			});
		},
		opencompany:function(o1,i){
			var d  = this.createdata[i];
			var cans = {url:'company/manage',num:'company'+d.num+'',name:''+d.name+'(管理)',params:{cnum:d.num}}
			addtabs(cans);
		},
		showdata:function(da){
			this.companyCreate(da.companyCreate);
			this.companyJoin(da.companyJoin);
			if(da.usershu){
				$('#totaldiv{rand}').show();
				$('#usershu{rand}').html(da.usershu);
				$('#companyshu{rand}').html(da.companyshu);
			}
			if(da.usertype>0)$('#createbtn_{rand}').show();
			js.initbtn(this);
		},
		companyCreate:function(da){
			this.createdata = da;
			var i=0,len = da.length,d,str='<div class="rock-list-item">我创建的单位</div>';
			for(i=0;i<len;i++){
				d = da[i];
				if(!d.logo)d.logo='images/nologo.png';
				str+='<div class="rock-list-item rock-hover">';
				str+='<img src="'+d.logo+'" class="radius5" height="24" width="24" align="absmiddle"> ';
				str+=''+d.name+'';
				str+=' <button clickevt="opencompany,'+i+'" class="webbtn webbtn-mini webbtn-default">管理</button>';
				str+='</div>';
			}
			var o1 = $('#create{rand}');
			o1.html(str);
			if(len==0)o1.hide();
		},
		create:function(){
			var call = 'winclss'+js.getrand()+'';
			window[call]=function(){
				c.inits();
			}
			xcy.openinput({name:'单位',num:'company',ismodal:true,callback:call});
		},
		openjoin:function(o1,i){
			var d  = this.joinData[i];
			xcy.opencompany(d, true);
		},
		openjihuo:function(o1,i){
			var d  = this.joinData[i];
			
		},
		companyJoin:function(da){
			this.joinData = da;
			var i=0,len = da.length,d,str='<div class="rock-list-item">我加入的单位</div>';
			for(i=0;i<len;i++){
				d = da[i];
				if(!d.logo)d.logo='images/nologo.png';
				str+='<div class="rock-list-item rock-hover">';
				str+='<img src="'+d.logo+'" class="radius5" height="24" width="24" align="absmiddle"> ';
				str+=''+d.name+'';
				if(d.state=='1'){
					//str+=' <span class="rock-badge bg-success">已激活</span>';
					str+=' <button clickevt="openjoin,'+i+'" class="webbtn webbtn-mini webbtn-default">进入单位</button>';
				}else{
					str+=' <span class="rock-badge bg-danger">待激活</span>';
					str+=' <button clickevt="openjihuo,'+i+'" class="webbtn webbtn-mini bg-danger">激活</button>';
				}
				
				str+='</div>';
			}
			$('#comjoin{rand}').html(str);
		}
	}
	c.inits();
});
</script>

<div style="margin:10px">

	<div style="display:none;" id="totaldiv{rand}">
		<div style="display:inline-block">
			<div class="rock-border rock-radius bg-main rock-hovers cursor" align="center" style="width:110px;padding:20px 0px;float:left;margin:10px;position:relative">
				<div style="font-size:30px" class="white"><i class="icon-user"></i></div>
				<div class="white">平台用户(<span id="usershu{rand}">0</span>)</div>
			</div>
			<div class="rock-border rock-radius bg-main rock-hovers cursor" align="center" style="width:110px;padding:20px 0px;float:left;margin:10px">
				<div style="font-size:30px" class="white"><i class="icon-road"></i></div>
				<div class="white">单位数(<span id="companyshu{rand}">0</span>)</div>
			</div>
		</div>
	</div>

	<div style="margin-top:10px;display:inline-block;">
		<div align="left" style="float:left;margin-right:15px">
			<div class="rock-panel rock-border rock-radius rock-list-group"  id="create{rand}">
				<div class="rock-list-item">我创建的单位</div>
			</div>
			<div align="center" id="createbtn_{rand}" style="padding:10px;display:none"><button clickevt="create" type="button" class="webbtn bg-success"><i class="icon-plus"></i> 新增单位</button></div>
		</div>
		<div align="left" style="float:left;" id="comjoin{rand}" class="rock-panel rock-border rock-radius rock-list-group">
			<div class="rock-list-item">我加入的单位</div>
		</div>
	
	</div>

</div>